package me.luger.project.fof.controller.api;

import me.luger.core.commom.util.DateUtil;
import me.luger.core.commom.util.LogUtil;
import me.luger.core.commom.util.StringUtil;
import me.luger.core.mvc.controller.BaseController;
import me.luger.core.mvc.entity.Result;
import me.luger.project.fof.entity.FundInfo;
import me.luger.project.fof.service.FundInfoService;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.ResponseBody;

import me.luger.project.fof.service.FofFundIndicatorService;

import java.util.*;

/**
 * 基金时序指标 controller
 */
@Controller
@RequestMapping("/api/fof/fofFundIndicator")
public class FofFundIndicatorApiController extends BaseController {

    @Autowired
    private FofFundIndicatorService fofFundIndicatorService;

    @Autowired
    private FundInfoService fundInfoService;

    @RequestMapping(value = "fundCombination",name = "接口描述")
    @ResponseBody
    public Object fundCombination(String fids){
        Map<String,Object> result = new HashedMap();
        try{
            String[] fidArr = fids.split(",");

            List<Map> fundProfitMapList = new ArrayList<Map>();
            List<List<Object>> fundProfitList = null;
            Map<String,Object> fundProfitMap = null;
            Map<String,Object> fundProfitListMap = new HashMap<String,Object>();
            for(String fid : fidArr){
                fundProfitMap = new HashMap<String,Object>();
                fundProfitList = new ArrayList<List<Object>>();
                fundProfitList = fofFundIndicatorService.getRangeProfit(DateUtil.add(Calendar.YEAR,-1),DateUtil.nowAsDate(),Integer.parseInt(fid));

                FundInfo fofFundInfo = fundInfoService.fetchById(Integer.parseInt(fid));
                if(null == fofFundInfo){
                    continue;
                }

                fundProfitMap.put("fid",fid);
                fundProfitMap.put("name",fofFundInfo.getFundNameShort());
                fundProfitMap.put("list",fundProfitList);

                fundProfitMapList.add(fundProfitMap);
            }
            result.put("fundsProfit",fundProfitMapList);
        }catch (Exception e){
            LogUtil.errorLog(e,"");
            return Result.error();
        }

        return Result.success(result);
    }

    @RequestMapping(value = "",name = "接口描述")
    @ResponseBody
    public Object demo(){
        try{

        }catch (Exception e){
            return Result.error();
        }
        return Result.success();
    }
}
